package icursoft.educationms.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import icursoft.educationms.util.CommUtil;


/**
 * Created by Administrator on 2016/10/12.
 */

public class CustomDialog extends Dialog {
    private static int default_width = 260; // 默认宽度
    private static int default_height = 165;// 默认高度

    public static int default_info_edit_width = 260; // 默认宽度
    public static int default_info_edit_height = 200;// 默认高度

    public CustomDialog(Context context, int layout, int style) {
        this(context, default_width, default_height, layout, style);
    }

    /**
     * width、height为0时自适应宽高
     * @param context
     * @param width
     * @param height
     * @param layout
     * @param style
     */
    public CustomDialog(Context context, int width, int height, int layout,
                        int style) {
        super(context, style);
        setContentView(layout);// set content
        Window window = getWindow();// set window params
        WindowManager.LayoutParams params = window.getAttributes();
        if(height>1){//规定高度
            params.height = CommUtil.dp2px(context, height);
        }else{
            //设置SelectPicPopupWindow弹出窗体的高
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        }
        if(width>1){//规定高度
            params.width = CommUtil.dp2px(context, width);
        }else{
            params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        }
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);
    }
    public void setGravity(){
        Window window = getWindow();// set window params
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.RIGHT|Gravity.TOP;
    }
    /**
     * 全屏
     */
    public CustomDialog(Context context, boolean isFullScreen, int layout,
                        int style) {
        super(context, style);
        setContentView(layout);// set content
        Window window = getWindow();// set window params
        WindowManager.LayoutParams params = window.getAttributes();
        if(isFullScreen){//规定高度
            params.height = WindowManager.LayoutParams.MATCH_PARENT;
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
        }
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);
    }
}

